<?php

class customerAction extends Action
{
    public function customeraddsave()
    {
        $customer = new customerModel();
        if (!$customer->create())
        {
            $this->error($customer->getError());
        }
        else
        {
            $id = $customer->add();
            $this->assign("jumpUrl", U("customer/customercontent", array('id' => $id)));
            $this->success("添加成功");
        }
    }

    public function customerlist()
    {
        $customer = new customerModel();
        import("ORG.Util.Page");
        $pagsize = 15;
        $totalnum = $customer->count();
        $list = $customer->page($_GET['p'])->order('id desc')->limit($pagsize)->select();
        $this->assign("list", $list);
        $page = new Page($totalnum, $pagsize);
        $page->rollPage = $pagsize;
        $page->setConfig("prev", "上一页");
        $page->setConfig("next", "下一页");
        $page->setConfig("first", "首页");
        $page->setConfig("last", "末页");
        $page->setConfig("theme", "共%totalRow%%header%条数据 %nowPage%/%totalPage%页  %first% %upPage%   %linkPage%  %downPage% %end%");
        $pageshow = $page->show();
        $this->assign("pageshow", $pageshow);
        $this->display();
    }

    public function customeradmin()
    {
        $customer = new customerModel();
        $condition["employee"] = I('session.userid');
        $condition["isdelete"] = 0;
        import("ORG.Util.Page");
        $totalnum = $customer->count();
        $name = I('post.sousuo', '', 'htmlspecialchars');
        if (isset($name))
        {
            $condition['company'] = array('like', "%{$name}%");
        }

        $list = $customer->page($_GET['p'])->limit(10)->where($condition)->select();

        $site = M("site");

        foreach ($list as $k => &$v)
        {
            $condition["projectid"] = $v["id"];
            $v["site"] = $site->where($condition)->select();
        }
        $this->assign("list", $list);
        $page = new Page($totalnum, 10);
        $page->rollPage = 10;
        $page->setConfig("prev", "上一页");
        $page->setConfig("next", "下一页");
        $page->setConfig("first", "首页");
        $page->setConfig("last", "末页");
        $page->setConfig("theme", "共%totalRow%%header%条数据 %nowPage%/%totalPage%页  %first% %upPage%   %linkPage%  %downPage% %end%");
        $pageshow = $page->show();
        $this->assign("pageshow", $pageshow);
        $this->display();
    }

    public function customerupdate()
    {
        $customer = new customerModel();
        $data = $customer->where("id='{$_GET['id']}'")->find();
        $this->assign("data", $data);
        $this->display();
    }

    public function customerupdatesave()
    {
        $customer = new customerModel();
        if (!$customer->create())
        {
            $this->error($customer->getError());
        }
        else
        {
            $customer->save();
            $this->assign("waitSecond", 1);
            $this->assign("jumpUrl", U("customer/customeradmin"));
            $this->success("修改成功");
        }
    }

    public function customercontent()
    {
        $customer = new customerModel();
        $data = $customer->where("id='{$_GET['id']}'")->find();
        $this->assign("data", $data);
        $this->display();
    }

    public function customerdel()
    {
        $customer = new customerModel();
        $data["id"] = I('get.id', 0);
        $data["isdelete"] = 1;
        if ($customer->save($data))
        {
            $this->error("删除失败");
        }
        else
        {
            $this->success("删除成功");
        }
    }

    public function _empty()
    {
        //空操作
        $this->error("您访问的页面不存在！");
    }

}

?>